﻿using BCCommon;
using BCCommon.TMS.Invoice;
using BCDto.TMS.User.UserInvoiceThin;
using BCService.TMS.User.UserInvoiceThin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.ClientApp.User
{
    /// <summary>
    /// 用户发票薄
    /// </summary>
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [Route("api/v1/ClientApp/[controller]")]
    public class UserInvoiceThinController : ClientAppBaseController
    {
        #region var
        private IUserInvoiceThinService userInvoiceThinService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public UserInvoiceThinController(IUserInvoiceThinService userInvoiceThinService)
        {
            this.userInvoiceThinService = userInvoiceThinService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新用户发票薄配置记录
        /// </summary>
        /// <param name="dto">用户发票薄配置数据模型</param>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(UserInvoiceThinDto), 201)]
        public IActionResult Post([FromBody] UserInvoiceThinRequestDto dto)
        {
            var result = this.userInvoiceThinService.Add(this.UserInfo, dto);
            return Ok(result);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改用户发票薄配置记录
        /// </summary>
        /// <param name="userInvoiceThinId">用户发票薄Id</param>
        /// <param name="dto">用户发票薄配置数据模型</param>
        /// <returns></returns>
        [HttpPut("{user_invoice_thin_id}")]
        [ProducesResponseType(typeof(UserInvoiceThinDto), 200)]
        public IActionResult Put([FromRoute(Name = "user_invoice_thin_id")] long userInvoiceThinId,
            [FromBody] UserInvoiceThinRequestDto dto)
        {
            var result = this.userInvoiceThinService.Update(this.UserInfo, userInvoiceThinId, dto);
            return this.Ok(result);
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除用户发票薄配置记录
        /// </summary>
        /// <param name="userInvoiceThinId">用户发票薄配置ID</param>
        /// <returns></returns>
        [HttpDelete("{user_invoice_thin_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "user_invoice_thin_id")] long userInvoiceThinId)
        {
            this.userInvoiceThinService.Delete(this.UserInfo, userInvoiceThinId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条用户发票薄配置记录
        /// </summary>
        /// <param name="userInvoiceThinId">用户发票薄配置ID</param>
        /// <returns></returns>
        [HttpGet("{user_invoice_thin_id}")]
        [ProducesResponseType(typeof(UserInvoiceThinDto), 200)]
        public IActionResult Get([FromRoute(Name = "user_invoice_thin_id")] long userInvoiceThinId)
        {
            var result = this.userInvoiceThinService.GetById(userInvoiceThinId);
            return this.Ok(result);
        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询用户发票薄配置
        /// </summary>
        /// <param name="invoiceTitleType">发票抬头类型</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<UserInvoiceThinDto>), 200)]
        public IActionResult Query([FromQuery(Name = "invoice_title_type")] InvoiceTitleType? invoiceTitleType,
            [FromQuery(Name = "page_index")] int pageIndex = 1, 
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.userInvoiceThinService.Query(this.UserInfo, invoiceTitleType, pageIndex, pageSize);
            return this.Ok(result);
        }
        #endregion

        #region List 
        /// <summary>
        /// 查询用户发票薄配置列表
        /// </summary>
        /// <param name="invoiceTitleType">发票抬头类型</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<UserInvoiceThinDto>), 200)]
        public IActionResult List([FromQuery(Name = "invoice_title_type")] InvoiceTitleType? invoiceTitleType)
        {
            var result = this.userInvoiceThinService.GetList(this.UserInfo, invoiceTitleType);
            return this.Ok(result);
        }
        #endregion
    }
}
